import numpy as np
import os
import argparse

args = argparse.ArgumentParser()
args.add_argument("--root-dir", type=str, default="../results")
args.add_argument("-mn", "--max-noise", type=float, default=3)
args.add_argument("-mo", "--max-outlier", type=float, default=0.3)
args = args.parse_args()
root_dir = args.root_dir
max_noise = args.max_noise
max_outlier = args.max_outlier
print("Method\tRecall\tPrecision\tF1\tRuntime(s)")

for file in os.listdir(root_dir):
    if file.endswith(".csv"):
        data = np.loadtxt(os.path.join(root_dir, file), delimiter=",")
        data[np.isnan(data)] = 0
        ind = (data[:, 0] <= max_noise) & (data[:, 2] <= max_outlier)
        r, t, p = data[ind, 3:].mean(axis=0)
        F1 = (
            2 * data[ind, 3] * data[ind, 5] / (data[ind, 3] + data[ind, 5] + 1e-6)
        ).mean()
        print(
            "{0}\t{1:3f}\t{2:3f}\t{3:3f}\t{4:3f}".format(
                file.removesuffix(".csv"), 100 * r, 100 * p, 100 * F1, t
            )
        )
